def is_prime(number: int) -> bool:
    for j in range(2, number):
        if number % j == 0:
            return False
    return True


nums = {
    'one': '1',
    'two': '2',
    'three': '3',
    'four': '4',
    'five': '5',
    'six': '6',
    'seven': '7',
    'eight': '8',
    'nine': '9',
    'zero': '0'
}
try:
    i = k = d1 = d2 = None
    n = int(''.join(nums[i] for i in input().split(' ')))
    if n > 0 and len(str(n)) == 3:
        for i in range(n, 1, -1):
            if is_prime(i):
                d1 = n-i
                break
        for k in range(n, n*9999):
            if is_prime(k):
                d2 = k-n
                break
        print(i if d1 <= d2 else k)
    else:
        print('Wrong input')
except KeyError:
    print('Wrong input')


